/**
 * 通用ProTable表格组件
 * 设置了默认配置，方便全局配置，可覆盖
 * 使用方法与其他属性与ProTable一致
 */
import { DEFAULT_PAGE_CONFIG } from '@/constants/global.const';
import type { ParamsType } from '@ant-design/pro-provider';
import type { ProTableProps } from '@ant-design/pro-table';
import ProTable from '@ant-design/pro-table';
import type { FC } from 'react';

const CommonTable: FC<ProTableProps<Record<string, any>, ParamsType, string>> = (props) => {
  const { pagination, search, ...restProps } = props || {};
  return (
    <ProTable
      bordered={false}
      tableLayout="fixed"
      cardBordered={false}
      scroll={{ x: '100%' }}
      options={false}
      revalidateOnFocus={false}
      // 分页相关配置
      pagination={
        (pagination || typeof pagination === 'undefined') && {
          size: 'default',
          showQuickJumper: false,
          showSizeChanger: true,
          showTotal: (total) => `共 ${total} 条`,
          pageSizeOptions: ['10', '20', '50', '100'],
          ...DEFAULT_PAGE_CONFIG,
          ...pagination,
        }
      }
      // 检索相关配置
      search={
        (search || typeof search === 'undefined') && {
          span: {
            xs: 24,
            sm: 12,
            md: 8,
            lg: 8,
            xl: 8,
            xxl: 6,
          },
          labelWidth: 'auto',
          collapseRender: false,
          defaultCollapsed: false,
          ...search,
        }
      }
      {...restProps}
    />
  );
};

export default CommonTable;
